home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / LCSUM.C < prev    next >
C/C++ Source or Header  |  1997-08-18  |  1KB  |  42 lines

  1. #ifdef UNIX
  2. /*
  3.  * Word aligned linear buffer checksum routine.  Called from mbuf checksum
  4.  * routine with simple args.  Intent is that this routine may be replaced
  5.  * by assembly language routine for speed if so desired. (On the PC, the
  6.  * replacement is in pcgen.asm.)
  7.  *
  8.  * Copyright 1991 Phil Karn, KA9Q
  9.  */
  10.  
  11. #if    (defined(MPU8086) || defined(MPU8080) || defined(vax))
  12. #define    IS_LITTLE_ENDIAN    /* Low order bytes are first in memory */
  13. #endif            /* Almost all other machines are big-endian */
  14. #include "global.h"
  15. #include "ip.h"
  16.  
  17. #if !defined(_lint)
  18. static char rcsid[] OPTIONAL = "$Id: lcsum.c,v 1.9 1997/08/19 01:19:22 root Exp root $";
  19. #endif
  20.  
  21.  
  22.  
  23. int16
  24. lcsum(wp,len)
  25. register int16 *wp;
  26. register int16 len;
  27. {
  28.     register int32 sum = 0;
  29.     int16 result;
  30.  
  31.     while(len-- != 0)
  32.         sum += *wp++;
  33.     result = eac(sum);
  34. #ifdef    IS_LITTLE_ENDIAN
  35.     /* Swap the result because of the (char *) to (int *) type punning */
  36.     result = (int16) (result << 8) | (result >> 8);
  37. #endif
  38.     return result;
  39. }
  40.  
  41. #endif        /* UNIX */
  42.